This page last changed on Mar 28, 2012 by jed.wheeler@involver.com.

In this Chapter:

  1. If-logic based localization
  2. Phrasebook manager and the localize tag

One of the great things about web development is that it has such a broad reach, people all over the world can use the same few basic tools to access content anywhere else. But what if you want to show different content to different people? SML has a range of tools available to do just that. Whether you want to build a fan gate that requires someone to “Like” your page before they can view its content or you want to target specific content to people according to language, country, or even ?klout score, you can do it in SML.

Adding Location and Language targeting

In ?Chapter 2 - Variables in SML we looked at if-logic using SML variables to add fan gates and even time release content.  We can use this same system to show/hide feature blocks and editable assets according to the users country and or language.  

  1. Update your code to now read:
    {% if current_language = "en" and current_country = "us" %}
        {% signup_form onsuccess:"showThankYouMessage();" rules_var:"sweeprules" %}
            <ol>
                <li><label for="name">Name:</label> <input type="text" name="name"></li>
                <li><label for="email">Email:</label> <input type="text" name="email"></li>
                <li><label for="phone number">Phone Number:</label> <input type="text" name="phone_no"></li>
    
                <p>{% signup_form_submit %}</p>
            </ol>
        {% endsignup_form %}
    
        <div id="thank_you_message" style="display:none">
            <h2>Thanks for entering! Check back here December 1st to see if you've won.</h2>
        </div>
    
        <script type="text/javascript">
        var sweeprules = {
         email: {
           required: true,
           email: true
         },
         name: {
           required: true
         },
         phone_no: {
           required: true
         }
        }
    
        function showThankYouMessage() {
          sml.get('signup_div').hide();
          sml.get('thank_you_message').show();
        }
        </script>
    
    {% elsif current_language = "es" and current_country = "us" %}
       <!-- spanish version of feature block block goes here. -->
    {% else %}
    This promotion is not available for your location or language.
    {% endif %}
    

Click "Save and test." The Save & Test button will launch a popup window that allows us to test how our page will appear for any given combination of language, country, and fan status. It also allows us to preview the app as it will appear on mobile and the open web, should we choose to take advantage of that functionality.

Using phrasebook_manager

If logic is a very powerful tool, but it can be cumbersome to write out a dozen if statements for each chunk of text you want to localize. For pages that will be pushed out to large global audiences, we recommend using the phrasebook_manager feature block to streamline this process.

With the phrasebook manager block instead of using ?editable_html to store your up-dateable text, you'll instead use the ?localize tag to call text strings according to the users language and country from a tsv file that you've uploaded in the feature block configuration.  Even better, multiple sml tabs can call from the same phrasebook manager block so you can update all the translations on all your tabs with a single upload by adding a new TSV file.  

Note that this does not work with text outputted from other feature blocks, only for stand alone plain text.  If you're outputting text from feature blocks and want to localize it you'll need to use if logic to swap between multiple instances of the same block, one for each language/country set you're supporting.

Document generated by Confluence on Feb 12, 2013 09:09